package com.Ajava1704.for设计模式.for动态代理.CGLIB;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 作者: LCG
 * 日期: 2020/2/14 09:13
 * 描述:
 */
public class ForMyMethodInterceptor<T> implements MethodInterceptor {

    private Enhancer enhancer=new Enhancer();

    public T getProxyObject(Class zclass){

        enhancer.setSuperclass(zclass);
        enhancer.setCallback(this);

        return (T)enhancer.create();
    }


    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

        System.out.println("=======为接口做代理，这是接口方法的实现=========");

        return "ok";
    }
}
